// Test village card

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

int main() {
    int r, handCount, handPos = 0;
    int pick1 = 0;
    int pick2 = 0;
    int pick3 = 0;
    int numPlayer = 2;
    int seed = 1000;
    int k[10] = {adventurer, council_room, feast, gardens, mine
        , remodel, smithy, village, baron, great_hall};
    struct gameState G;
    int maxHandCount = 5;
    int deckCount = 5;
    int cardChange = 1;
    int player_hand[maxHandCount];
    int intialDeckCount;
    int intialHandCount;
    int nextDeckCount;
    int nextHandCount;
    
	player_hand[0] = village;
	player_hand[1] = copper;
	player_hand[2] = silver;
	player_hand[3] = estate;
    
#if (NOISY_TEST == 1)
    printf ("TESTING village card:\n");
#endif
    
	for (handCount = 1; handCount <= maxHandCount; handCount++)
    {
#if (NOISY_TEST == 1)
		printf("Test player with card hand count of %d.\n",handCount);
#endif
		memset(&G, 23, sizeof(struct gameState));   // clear the game state
	    r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
		G.handCount[0] = handCount;                 // set the number of cards on hand
		memcpy(G.hand[0], player_hand, sizeof(int) * handCount); // set all the cards to player_hand
		intialDeckCount = G.deckCount[0];
		intialHandCount = G.handCount[0];
		
		r = playCard(handPos, pick1, pick2, pick3, &G);
		nextDeckCount = G.deckCount[0];
		nextHandCount = G.handCount[0];

        
#if (NOISY_TEST == 1)
        printf("intial deck count = %d\n", intialDeckCount);
        printf("next deck count = %d\n", nextDeckCount);
        printf("expected = %d.\n", deckCount - cardChange);
        
        printf("intial hand count = %d\n", intialHandCount);
        printf("next hand count = %d\n", nextHandCount);
        printf("expected = %d.\n\n", handCount -1 + cardChange);

#endif
		
		assert(nextDeckCount == deckCount - cardChange);
		assert(nextHandCount == handCount -1 + cardChange);
		
	}
    
    printf("All tests passed!\n");
    
    return 0;
}
